package api

import (
	"api-gateway/basic/inits"
	__ "api-gateway/basic/proto"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"github.com/gin-gonic/gin"
)

// AddInstrument
// @Summary      仪器添加
// @Description  仪器添加
// @Tags         仪器添加
// @Accept       json
// @Produce      json
// @Param        user  body      request.AddInstrument  true  "仪器参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Router       /instrument/addInstrument [post]
func AddInstrument(c *gin.Context) {
	var req request.AddInstrument
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}

	instrument, err := inits.UserCline.Instrument(c, &__.InstrumentReq{
		UserId:                      req.UserId,
		TempValue:                   float32(req.TempValue),
		BloodSugarValue:             float32(req.BloodSugarValue),
		SystolicBloodPressureValue:  float32(req.SystolicBloodPressureValue),
		DiastolicBloodPressureValue: float32(req.DiastolicBloodPressureValue),
		BloodOxygenValue:            float32(req.BloodOxygenValue),
		DeviceID:                    req.DeviceID,
	})
	if err != nil {
		response.Error(c, 500, "服务器连接错误", err.Error())
		return
	}

	response.Error(c, 200, "添加成功", instrument)
}
